Skip to content

Add RISC-V RVV optimization support for zstd C library compilation#355

Open
Dayuxiaoshui wants to merge 2 commits intogyscos:mainfrom
Dayuxiaoshui:main
Open

Add RISC-V RVV optimization support for zstd C library compilation#355
Dayuxiaoshui wants to merge 2 commits intogyscos:mainfrom
Dayuxiaoshui:main

Conversation

@Dayuxiaoshui
Copy link
Copy Markdown

This commit adds automatic RISC-V RVV (RISC-V Vector Extension) optimization support when building the zstd C library on RISC-V 64-bit platforms.

Changes:

  • Detect riscv64 target architecture in build.rs

  • Automatically apply -march=rv64gcv flag (with fallback to -march=rv64gc)

  • Add -O3 optimization level for RISC-V builds

  • Use flag_if_supported_with_fallbacks to gracefully handle unsupported flags

The optimization is automatically applied when compiling on riscv64 targets, with graceful fallback if the compiler doesn't support RVV extensions.

Tested on:

  • RISC-V 64-bit platform (riscv64)

  • All tests pass (32 unit tests + 1 integration test + 4 doc tests)

  • Build successful with both debug and release profiles

This enables better performance for zstd compression/decompression on RISC-V platforms that support vector extensions.

This commit adds automatic RISC-V RVV (RISC-V Vector Extension) optimization support when building the zstd C library on RISC-V 64-bit platforms.

Changes:

- Detect riscv64 target architecture in build.rs

- Automatically apply -march=rv64gcv flag (with fallback to -march=rv64gc)

- Add -O3 optimization level for RISC-V builds

- Use flag_if_supported_with_fallbacks to gracefully handle unsupported flags

The optimization is automatically applied when compiling on riscv64 targets, with graceful fallback if the compiler doesn't support RVV extensions.

Tested on:

- RISC-V 64-bit platform (riscv64)

- All tests pass (32 unit tests + 1 integration test + 4 doc tests)

- Build successful with both debug and release profiles

This enables better performance for zstd compression/decompression on RISC-V platforms that support vector extensions.

Co-authored-by: gong-flying <gongxiaofei24@iscas.ac.cn>
@gyscos
Copy link
Copy Markdown
Owner

gyscos commented Dec 25, 2025

Hi, and thanks for the PR!

Everything looks fine - I'm just wondering if the -O3 should be conditional on the optimization level requested, rather than always applied?

@Dayuxiaoshui
Copy link
Copy Markdown
Author

Thanks for the feedback! You're absolutely right. I've updated the patch to only apply -O3 for release builds by checking the PROFILE environment variable. This respects the user's build configuration - debug builds will use default optimization levels while release builds get the performance benefits of -O3. The patch has been updated accordingly.

Update RISC-V RVV optimization to only apply -O3 flag in release builds, respecting the optimization level requested by the user.

This addresses the review feedback to make optimization level conditional rather than always applied.

Co-authored-by: gong-flying <gongxiaofei24@iscas.ac.cn>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants